﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using Tauren.Form.Entity.Output;
using Tauren.Form.Infrastructure;
using Tauren.Form.Infrastructure.Common;
using Tauren.Form.Service.Field_FormBLL;
using Tauren.Form.Service.Form_TableInfoBLL;

namespace Tauren.Form.Core.Controllers.V2._0
{
    /// <summary>
    /// 表单信息接口-v2.0
    /// </summary>
    [Route("api/form/v{version:apiVersion}"), ApiVersion("2.0")]
    [ApiController]
    public class Field_FormController : ControllerBase
    {
        private IField_FormService service;
        private IFieldService fieldService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="services"></param>
        public Field_FormController(IEnumerable<IField_FormService> services)
        {
            this.service = services.FirstOrDefault(o => o.VersionName == 2.0);
            if (this.service == null) throw new ApiVersionException("不支持当前版本");
        }
        /// <summary>
        /// 分页获取 单位信息列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("pages")]
        public IActionResult Pages([FromBody] Entity.Global.QueryModel queryModel) => service.Pages(queryModel).ToJsonResult();

         

        /// <summary>
        /// 表单字段
        /// </summary>
        /// <param name="FormId">ID</param> 
        ///  /// <param name="VersionId">表单版本ID</param> 
        /// <returns></returns>
        [HttpPost, Route("fields/{FormId}")]
        public IActionResult FormFields([FromRoute] long FormId, [FromQuery] long VersionId = 0) => fieldService.FormFields(FormId, VersionId).ToJsonResult();

        /// <summary>
        /// 添加区域信息
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("tables")]
        public IActionResult Tables([FromBody] Entity.Global.QueryModel queryModel) => fieldService.TableInfos(queryModel).ToJsonResult();

    }
}
